import { PolygonLayer } from '@antv/l7';
import type { TestCase } from '../../types';
import { CaseScene } from '../../utils';

const data1 = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      id: '01',
      properties: {
        id: 1,
        density: 11,
        area: 3.141592653589793,
        rightPos: {
          lng: 120.20854679009427,
          lat: 30.289759312473567,
        },
      },
      geometry: {
        type: 'Polygon',
        coordinates: [
          [
            [120.21773200000003, 30.302992203637245],
            [120.21875298581796, 30.302948894941498],
            [120.21976413630021, 30.302819386054836],
            [120.22075571093397, 30.302604924556675],
            [120.22171815793494, 30.302307576377434],
            [120.22264220632778, 30.30193020588136],
            [120.22351895531074, 30.301476448252767],
            [120.22433996004101, 30.30095067445258],
            [120.22509731301196, 30.300357949084106],
            [120.22578372023696, 30.29970398157531],
            [120.22639257150433, 30.298995071149374],
            [120.22691800402723, 30.29823804611518],
            [120.22735495887522, 30.297440198064148],
            [120.2276992296457, 30.296609211608768],
            [120.22794750290792, 30.295753090341062],
            [120.22809739003313, 30.294880079725182],
            [120.22814745010669, 30.293998587668092],
            [120.2280972037059, 30.293117103533838],
            [120.22794713741399, 30.292244116382022],
            [120.22769869903073, 30.291388033217864],
            [120.22735428353045, 30.290557098041248],
            [120.22691720990578, 30.289759312473567],
            [120.22639168912384, 30.289002358726105],
            [120.2257827835068, 30.288293525650804],
            [120.22509635793018, 30.287639638583972],
            [120.22433902331086, 30.28704699365746],
            [120.22351807293023, 30.286521297207894],
            [120.22264141220631, 30.286067610866056],
            [120.22171748259014, 30.285690302853336],
            [120.22075518031896, 30.285393005952855],
            [120.21976377080624, 30.285178582558256],
            [120.21875279949074, 30.28504909713565],
            [120.21773200000003, 30.285005796362746],
            [120.2167112005093, 30.28504909713565],
            [120.21570022919379, 30.285178582558256],
            [120.21470881968106, 30.285393005952855],
            [120.21374651740989, 30.285690302853336],
            [120.21282258779372, 30.286067610866056],
            [120.21194592706979, 30.286521297207894],
            [120.21112497668918, 30.28704699365746],
            [120.21036764206985, 30.287639638583972],
            [120.20968121649322, 30.288293525650804],
            [120.20907231087618, 30.289002358726105],
            [120.20854679009427, 30.289759312473567],
            [120.2081097164696, 30.290557098041248],
            [120.20776530096931, 30.291388033217864],
            [120.20751686258605, 30.292244116382022],
            [120.20736679629412, 30.293117103533838],
            [120.20731654989335, 30.293998587668092],
            [120.2073666099669, 30.294880079725182],
            [120.2075164970921, 30.295753090341062],
            [120.20776477035433, 30.296609211608768],
            [120.20810904112481, 30.297440198064148],
            [120.20854599597281, 30.29823804611518],
            [120.2090714284957, 30.298995071149374],
            [120.20968027976308, 30.29970398157531],
            [120.21036668698808, 30.300357949084106],
            [120.21112403995903, 30.30095067445258],
            [120.21194504468929, 30.301476448252767],
            [120.21282179367225, 30.30193020588136],
            [120.2137458420651, 30.302307576377434],
            [120.21470828906605, 30.302604924556675],
            [120.21569986369981, 30.302819386054836],
            [120.21671101418207, 30.302948894941498],
            [120.21773200000003, 30.302992203637245],
          ],
        ],
      },
    },
  ],
};
const data2 = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: {
        id: 2,
        density: 22,
        area: 12.566370614359172,
        rightPos: {
          lng: 120.23505049603307,
          lat: 30.284005147499958,
        },
      },
      geometry: {
        type: 'Polygon',
        coordinates: [
          [
            [120.21773200000003, 30.3119854072745],
            [120.21977415806383, 30.311898781955875],
            [120.2217966382881, 30.311639740706045],
            [120.22377995275484, 30.311210779586737],
            [120.22570499154422, 30.31061603192496],
            [120.22755320713961, 30.309861228422253],
            [120.22930679337095, 30.30895364185113],
            [120.23094885716118, 30.30790201687569],
            [120.23246358141103, 30.306716485677736],
            [120.23383637744625, 30.305408470206746],
            [120.23505402555502, 30.303990572002014],
            [120.23610480225926, 30.30247645065471],
            [120.23697859309758, 30.30088069208723],
            [120.23766698983658, 30.299218667924997],
            [120.23816337118332, 30.297506387321075],
            [120.2384629662307, 30.295760342665886],
            [120.23856290003819, 30.293997350672402],
            [120.23846222092192, 30.29223439037028],
            [120.2381619092075, 30.290488439571295],
            [120.23766486737671, 30.28877631138159],
            [120.23697589171853, 30.287114492334393],
            [120.23610162577349, 30.285518983700303],
            [120.23505049603307, 30.284005147499958],
            [120.2338326305257, 30.282587558697713],
            [120.23245976108386, 30.281279864994566],
            [120.2309451102405, 30.28009465556447],
            [120.22930326384879, 30.27904333999154],
            [120.22755003065353, 30.2781360385674],
            [120.22570229016483, 30.277381484998127],
            [120.22377783029464, 30.27678694245142],
            [120.22179517631207, 30.27635813374636],
            [120.21977341275489, 30.276099186352752],
            [120.21773200000003, 30.276012592725507],
            [120.21569058724513, 30.276099186352752],
            [120.21366882368797, 30.27635813374636],
            [120.21168616970539, 30.27678694245142],
            [120.2097617098352, 30.277381484998127],
            [120.20791396934649, 30.2781360385674],
            [120.20616073615126, 30.27904333999154],
            [120.20451888975954, 30.28009465556447],
            [120.20300423891617, 30.281279864994566],
            [120.20163136947436, 30.282587558697713],
            [120.20041350396696, 30.284005147499958],
            [120.19936237422655, 30.285518983700303],
            [120.1984881082815, 30.287114492334393],
            [120.19779913262333, 30.28877631138159],
            [120.19730209079252, 30.290488439571295],
            [120.19700177907811, 30.29223439037028],
            [120.19690109996185, 30.293997350672402],
            [120.19700103376933, 30.295760342665886],
            [120.19730062881672, 30.297506387321075],
            [120.19779701016346, 30.299218667924997],
            [120.19848540690245, 30.30088069208723],
            [120.19935919774078, 30.30247645065471],
            [120.20040997444504, 30.303990572002014],
            [120.20162762255377, 30.305408470206746],
            [120.20300041858901, 30.306716485677736],
            [120.20451514283886, 30.30790201687569],
            [120.20615720662907, 30.30895364185113],
            [120.20791079286045, 30.309861228422253],
            [120.2097590084558, 30.31061603192496],
            [120.21168404724521, 30.311210779586737],
            [120.21366736171194, 30.311639740706045],
            [120.21568984193621, 30.311898781955875],
            [120.21773200000003, 30.3119854072745],
          ],
        ],
      },
    },
  ],
};
const data3 = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: {
        id: 3,
        area: 28.274333882308138,
        density: 1,
        rightPos: {
          lng: 120.21773200000003,
          lat: 30.320978610911727,
        },
      },
      geometry: {
        type: 'Polygon',
        coordinates: [
          [
            [120.21773200000003, 30.320978610911727],
            [120.22079551683832, 30.320848661038823],
            [120.22382950615737, 30.320460063936846],
            [120.22680472573462, 30.31981656505397],
            [120.22969250115753, 30.318924366581857],
            [120.23246500279812, 30.31779206753472],
            [120.23509551454973, 30.31643058067988],
            [120.23755869170974, 30.314853027129736],
            [120.2398308055025, 30.313074609622266],
            [120.24188997187018, 30.311112465724232],
            [120.24371636231784, 30.308985502385614],
            [120.24529239477944, 30.306714213454125],
            [120.24660290266935, 30.304320481922765],
            [120.24763528050285, 30.301827368829496],
            [120.24837960469955, 30.29925889085592],
            [120.24882872843001, 30.29663978877863],
            [120.24897834961936, 30.29399528901298],
            [120.24882705148536, 30.29135086055287],
            [120.24837631525429, 30.288731969652023],
            [120.24763050496843, 30.286163834610385],
            [120.2465968245668, 30.28367118302587],
            [120.2452852476867, 30.281278013844588],
            [120.24370842089364, 30.27900736649369],
            [120.24188154129892, 30.276881099310618],
            [120.2398222097663, 30.27491967939022],
            [120.23755026113787, 30.273141985860427],
            [120.2350875731244, 30.27156512846593],
            [120.23245785570393, 30.270204283191838],
            [120.22968642305335, 30.26907254649496],
            [120.2267999501987, 30.2681808095318],
            [120.22382621671096, 30.26753765358102],
            [120.22079383989308, 30.267149267655576],
            [120.21773200000003, 30.267019389088258],
            [120.21467016010696, 30.267149267655576],
            [120.21163778328908, 30.26753765358102],
            [120.20866404980134, 30.2681808095318],
            [120.2057775769467, 30.26907254649496],
            [120.2030061442961, 30.270204283191838],
            [120.20037642687565, 30.27156512846593],
            [120.19791373886217, 30.273141985860427],
            [120.19564179023374, 30.27491967939022],
            [120.19358245870113, 30.276881099310618],
            [120.19175557910638, 30.27900736649369],
            [120.19017875231334, 30.281278013844588],
            [120.18886717543323, 30.28367118302587],
            [120.18783349503161, 30.286163834610385],
            [120.18708768474575, 30.288731969652023],
            [120.18663694851467, 30.29135086055287],
            [120.18648565038066, 30.29399528901298],
            [120.18663527157001, 30.29663978877863],
            [120.18708439530049, 30.29925889085592],
            [120.18782871949719, 30.301827368829496],
            [120.18886109733069, 30.304320481922765],
            [120.1901716052206, 30.306714213454125],
            [120.1917476376822, 30.308985502385614],
            [120.19357402812986, 30.311112465724232],
            [120.19563319449753, 30.313074609622266],
            [120.19790530829029, 30.314853027129736],
            [120.2003684854503, 30.31643058067988],
            [120.2029989972019, 30.31779206753472],
            [120.2057714988425, 30.318924366581857],
            [120.20865927426541, 30.31981656505397],
            [120.21163449384267, 30.320460063936846],
            [120.21466848316172, 30.320848661038823],
            [120.21773200000003, 30.320978610911727],
          ],
        ],
      },
    },
  ],
};

export const removeMutiLayer: TestCase = async (options) => {
  const scene = await CaseScene({
    ...options,
    mapConfig: {
      center: [120.11155128479004, 30.24868703665976],
      zoom: 11,
    },
  });

  const layer = new PolygonLayer({})
    .source(data1)
    .scale('density', {
      type: 'quantile',
    })
    .color('#1990ff1a')
    .shape('fill');
  scene.addLayer(layer);

  const layer2 = new PolygonLayer({})
    .source(data2)
    .scale('density', {
      type: 'quantile',
    })
    .color('#1990ff1a')
    .shape('fill');
  scene.addLayer(layer2);

  const layer3 = new PolygonLayer({})
    .source(data3)
    .scale('density', {
      type: 'quantile',
    })
    .color('#1990ff1a')
    .shape('fill');
  scene.addLayer(layer3);

  removeMutiLayer.extendGUI = (gui) => {
    return [
      gui.add(
        {
          removeLayer: () => {
            const layers = scene.getLayers();
            for (const layer of layers) {
              scene.removeLayer(layer);
            }
          },
        },
        'removeLayer',
      ),
    ];
  };

  return scene;
};
